package com.study.example.study.extension.easyexcel.read;

import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * easyexcel 读数据提供枚举类
 *
 * @author RenYuLiang
 */
@Getter
public enum EasyExcelReadStrategyEnum {


    /**
     * 测试
     */
    TEST("test", 10,
            new String[]{"testEasyExcelReadDataHandlerStrategy", "testEasyExcelReadDataHandlerStrategy",
                    "testEasyExcelReadDataHandlerStrategy", "testEasyExcelReadDataHandlerStrategy",
                    "testEasyExcelReadDataHandlerStrategy", "testEasyExcelReadDataHandlerStrategy",
                    "testEasyExcelReadDataHandlerStrategy", "testEasyExcelReadDataHandlerStrategy",
                    "testEasyExcelReadDataHandlerStrategy", "testEasyExcelReadDataHandlerStrategy"});

    /**
     * 写数据类型
     */
    private final String type;
    /**
     * sheet 数量
     */
    private final Integer sheetNum;
    /**
     * excel 数据处理类 顺序须和 excel 顺序保持一致
     * 数量须和 sheetNum 保持一致
     */
    private final String[] readHandlerArray;

    EasyExcelReadStrategyEnum(String type, Integer sheetNum, String[] readHandlerArray) {
        this.type = type;
        this.sheetNum = sheetNum;
        this.readHandlerArray = readHandlerArray;
    }

    /**
     * 根据 name 获取 EasyExcelWriteStrategyEnum
     *
     * @param name 类似 TEST
     * @return EasyExcelWriteStrategyEnum
     */
    public static EasyExcelReadStrategyEnum getByName(final String name) {
        return EasyExcelReadStrategyEnum.valueOf(name);
    }

    /**
     * 根据 type 获取 EasyExcelWriteStrategyEnum
     *
     * @param type String
     * @return EasyExcelWriteStrategyEnum
     */
    public static EasyExcelReadStrategyEnum getByType(final String type) {
        return Arrays.stream(EasyExcelReadStrategyEnum.values()).filter(e -> Objects.equals(type, e.type)).findFirst().orElse(null);
    }


}
